/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.longview.io.modules.grassfeedback.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.longview.io.common.config.Global;
import com.longview.io.common.persistence.Page;
import com.longview.io.common.web.BaseController;
import com.longview.io.common.utils.StringUtils;
import com.longview.io.modules.grassfeedback.entity.GrassFeedback;
import com.longview.io.modules.grassfeedback.service.GrassFeedbackService;

/**
 * 意见反馈Controller
 * @author LDN
 * @version 2018-10-24
 */
@Controller
@RequestMapping(value = "${adminPath}/grassfeedback/grassFeedback")
public class GrassFeedbackController extends BaseController {

	@Autowired
	private GrassFeedbackService grassFeedbackService;
	
	@ModelAttribute
	public GrassFeedback get(@RequestParam(required=false) String id) {
		GrassFeedback entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = grassFeedbackService.get(id);
		}
		if (entity == null){
			entity = new GrassFeedback();
		}
		return entity;
	}
	
	@RequiresPermissions("grassfeedback:grassFeedback:view")
	@RequestMapping(value = {"list", ""})
	public String list(GrassFeedback grassFeedback, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GrassFeedback> page = grassFeedbackService.findPage(new Page<GrassFeedback>(request, response), grassFeedback); 
		model.addAttribute("page", page);
		return "modules/grassfeedback/grassFeedbackList";
	}

	@RequiresPermissions("grassfeedback:grassFeedback:view")
	@RequestMapping(value = "form")
	public String form(GrassFeedback grassFeedback, Model model) {
		model.addAttribute("grassFeedback", grassFeedback); 
		return "modules/grassfeedback/grassFeedbackForm";
	}

	@RequiresPermissions("grassfeedback:grassFeedback:edit")
	@RequestMapping(value = "save")
	public String save(GrassFeedback grassFeedback, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, grassFeedback)){
			return form(grassFeedback, model);
		}
		grassFeedbackService.save(grassFeedback);
		addMessage(redirectAttributes, "保存意见反馈成功");
		return "redirect:"+Global.getAdminPath()+"/grassfeedback/grassFeedback/?repage";
	}
	
	@RequiresPermissions("grassfeedback:grassFeedback:edit")
	@RequestMapping(value = "delete")
	public String delete(GrassFeedback grassFeedback, RedirectAttributes redirectAttributes) {
		grassFeedbackService.delete(grassFeedback);
		addMessage(redirectAttributes, "删除意见反馈成功");
		return "redirect:"+Global.getAdminPath()+"/grassfeedback/grassFeedback/?repage";
	}

}